package com.example.newdemo.list;

import android.util.Log;
import android.util.SparseArray;

public class SparaseArrayDemo {

    public static void main(String[] args) {
        testDemo();
    }


    public static void testDemo(){
        SparseArray<Object> sparseArray = new SparseArray<>();
        sparseArray.put(0,null);
        sparseArray.put(1,"fsdfd");
        sparseArray.put(2,new String("fjdslfjdk"));
        sparseArray.put(2,new String("111111"));
        sparseArray.put(3,1);
        sparseArray.put(4,new Boolean(true));
        sparseArray.put(5,new Object());
        sparseArray.put(8,new String("42fsjfldk"));
        sparseArray.put(20,"jfslfjdkfj");
        sparseArray.put(0,"chongfude");

        int size = sparseArray.size();
        for (int i = 0;i < size;i++) {
            int index=sparseArray.keyAt(i);
            Log.d("tag", "sparseArraySample: i = " + i + "  ; index = "+index+" ;value = " + sparseArray.get(index) );
        }
    }



}
/*
*  D/tag: sparseArraySample: i = 0  ; index = 0 ;value = chongfude
1 D/tag: sparseArraySample: i = 1  ; index = 1 ;value = fsdfd
D/tag: sparseArraySample: i = 2  ; index = 2 ;value = fjdslfjdk
D/tag: sparseArraySample: i = 3  ; index = 3 ;value = 1
D/tag: sparseArraySample: i = 4  ; index = 4 ;value = true
D/tag: sparseArraySample: i = 5  ; index = 5 ;value = java.lang.Object@2198cf6
D/tag: sparseArraySample: i = 6  ; index = 8 ;value = 42fsjfldk
D/tag: sparseArraySample: i = 7  ; index = 20 ;value = jfslfjdkfj
* */